home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / crsbas.zip / CROSSBAS.BAS < prev    next >
BASIC Source File  |  1990-12-01  |  56KB  |  1,408 lines

  1. '┌─────────────────────────────────────────────────────────────────────┐
  2. '└── beginning of crossbas.bas ────────────────────────────────────────┘
  3. '┌─────────────────────────────────────────────────────────────────────┐
  4. '│ CrossBas.bas                                                        │
  5. '│                                                                     │
  6. '│ This program will scan a Power-BASIC source file and create a cross-│
  7. '│ reference table of variable names and labels.  To do this we must   │
  8. '│ first read in all words in the file.  We can skip all text to the   │
  9. '│ right of "REM" or "'" remark identifiers.  After words are read in, │
  10. '│ we must compare them with PBASIC reserved words and metastatements. │
  11. '│ Finally, we alphabetize the remaining words and print them out, one │
  12. '│ word to a line, followed by the line number(s) where these words    │
  13. '│ were found.  The list will bs sorted without regard to case.        │
  14. '│                                                                     │
  15. '│ Command Line Switches:                                              │
  16. '│   /BW  Set screen colors to Black & White                           │
  17. '│   /U      Print all cross-reference variables in upper-case.           │
  18. '│   /P      Print page headers and footers.                              │
  19. '│   /S      Print cross-reference list to the screen as well as to file. │
  20. '│   /L:n Left margin n spaces.                                        │
  21. '│   /W:n Word array dimension over-ride.                              │
  22. '│                                                                     │
  23. '│                                                                     │
  24. '│ Modification History:                                               │
  25. '│                                                                     │
  26. '│ Uploaded CrossBas version 1.00P to Compuserve PCVENB, Spectra       │
  27. '│     forum.  Converted for Power-BASIC.               12/ 1/90       │
  28. '│                                                                     │
  29. '│ Added /bw switch to allow black and white screen color override.    │
  30. '│     Also, added color to default screen.             12/ 1/90       │
  31. '│                                                                     │
  32. '│ Uploaded CrossBas version 1.00 to  CompuServe BPROGA forum, LIB 9.  │
  33. '│     (Originally written for and in Turbo-BASIC.)                    │
  34. '│                                                                     │
  35. '│ KEYWORDS:  CROSS-REFERENCE, TABLE, LIST, NON-RESERVED WORDS         │
  36. '│                                                                     │
  37. '│ Description:  CrossBas will read in a Turbo-BASIC source file and   │
  38. '│     create an alphabetized cross-reference listing of non-          │
  39. '│     reserved words, i.e., variable, sub-program, function and       │
  40. '│     label names, along with the physical line number(s) where they  │
  41. '│     appear.  The list is printed to file.  Handy for cleaning       │
  42. '│     up unused variable names, labels, etc.           11/13/89       │
  43. '│                                                                     │
  44. '│ You are free to use this program as you wish.  If you find any      │
  45. '│ problems with if, please let me know about it.  If you have any     │
  46. '│ suggestions as to how to improve is, also, I'd appreciate your      │
  47. '│ help.                                                               │
  48. '│                                                                     │
  49. '│                                                                     │
  50. '│            Lester L. Noll  CompuServe id: 72250,2551                │
  51. '│            copyright (c) 11/13/89, 1990                             │
  52. '│                                                                     │
  53. '└─────────────────────────────────────────────────────────────────────┘
  54.   Title$     ="CrossBas.bas"
  55.   Ver$       ="1.00P"
  56.   Copyright$ ="Copyright (c) 11/13/90,  Lester L. Noll"
  57.   CisId$     ="72250,2551"
  58.  
  59. '┌── main program ─────────────────────────────────────────────────────┐
  60. Main:
  61.  
  62.     GOSUB Initialize            'Initialize screen, integers.
  63.     GOSUB InitScreen            'Put up init screen.
  64.     GOSUB ReadCmdLine                   'Read the DOS command line.
  65.     GOSUB OpenFiles            'Open source files and check name
  66.                         ' validity.
  67.     GOSUB CalcFileNames            'Parse filename from full path.
  68.     GOSUB ReadDefaults           'Read defaults from default file.
  69. '   GOSUB CheckStringSpace        'Check there is enough string space
  70.                     ' for infile words.
  71.                     '(Took this out for PBASIC version)
  72.     GOSUB CalcWordArraySize        'Calc word array dimension.
  73.     GOSUB PrintScreenTop        'Print top of screen report.
  74.     GOSUB ReadAndParseData        'Read source file lines and parse
  75.                     ' them into words.
  76.     GOSUB PrintScreen1            'Print read and parse report.
  77.     GOSUB Compare            'Compare source words with Power-
  78.                         ' BASIC reserved words.
  79.     GOSUB PrintScreen2            'Print compare report.
  80.     GOSUB SortWords            'Sort non-reserved words.
  81.     GOSUB PrintScreen3            'Print sort report.
  82.     GOSUB PrintList            'Print sorted words to file.
  83.     GOSUB PrintReportBtm        'Print summary report to file.
  84.     GOSUB PrintScreen4            'Print print-list report.
  85.     CLOSE
  86.     DELAY 1
  87.     CALL FlushKeyBuf
  88.   END
  89.  
  90. '└─────────────────────────────────────────────────────────────────────┘
  91.  
  92. '─── initialize ────────────────────────────────────────────────────────
  93. Initialize:
  94.  
  95.     $DYNAMIC                'All arrays default to dynamic. They
  96.                         ' can be erased after you're finished
  97.                         ' using them.
  98.     SCREEN 0,1: WIDTH 80: CLS        'Color board, 80 columns.
  99.     CLOSE                'Close all open files.
  100.     DEFINT A-Z                'Default all numbers to integer.
  101.     FG =14                'Foreground color.
  102.     BG =1                'Background color.
  103.     KEY OFF                'Turn BASIC soft keys off.
  104.     DIM SaveRow(10), SaveCol(10)    'Screen location arrays.
  105.     ON ERROR GOTO MemoryError           'Memory and other error trap.
  106.   RETURN
  107.  
  108. '─── print init screen ─────────────────────────────────────────────────
  109. InitScreen:
  110.  
  111.     COLOR FG,BG
  112.     LOCATE 10,18
  113.     PRINT "Initializing CrossBas.   Please wait ";
  114.     COLOR FG+16,BG            'Blink screen.
  115.     PRINT "..."
  116.     COLOR FG,BG
  117.   RETURN
  118.  
  119. '─── include files ─────────────────────────────────────────────────────
  120. $INCLUDE "crossbas.inc"            'CrossBas subprograms file.
  121.  
  122. '─── read command line ─────────────────────────────────────────────────
  123. ReadCmdLine:            'Read the DOS command line and use variables found
  124.                         ' there as the input PBASIC source file, the output
  125.                         ' cross-reference table file, and the '/u,' '/s,'
  126.                         ' '/l:n,' '/w:n,' and '/p' switches.  The first
  127.                         ' variable that doesn't start with one of the switch
  128.                         ' strings is assumed to be the source.  If a second
  129.                         ' such string is found, it is assumed to be the output 
  130.                         ' file.  If no output file is found, the input filename
  131.                         ' appended with '.cb' becomes the output filename.
  132.                         ' Other than input/output filename sequence, other
  133.                         ' parameters can be entered in any order.
  134.  
  135.     ON ERROR GOTO MemoryError            'Memory and other errors trap.
  136.     PageFlag =0        'Print page breaks and headers (1).
  137.     ScreenFlag =0    'Print list to screen also (1).
  138.     UcaseFlag =0    'Print list in upper-case (1).
  139.     LMarginMax =8    'Max left margin value.
  140.     WordDimFlag =0    'Word array dimension over-ride flag.
  141.     WordArrayDim =0    'Word array dimension over-ride.
  142.     InFile$ =""         'Input (source) file name and path.
  143.     OutFile$ =""    'Output file name and path.
  144.  
  145.     CALL DimCmdLine(DimCmd)        'Get number of parameters on cmd line.
  146.     DIM Parameter$(1:DimCmd)         'Max number of cmd line parameters.
  147.     CALL ParseCmdLine(Parameter$())    'Get command line parameters.
  148.  
  149.     FOR I = 1 TO DimCmd
  150.       SELECT CASE LEFT$(UCASE$(Parameter$(I)),2)'Check the left two
  151.                               ' characters of the DOS command
  152.                         ' line pa